<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        const el = console.log;
        const foo = 'baz'
        const bar = {
            foo
        }

        el(bar)

        function f(x, y) {
            const budai = 1
            return {
                x,
                y,
                budai,
            }
        }

        const o = {
            methods() {
                return 'hellojs'
            }
        }

        const obj1 = {
            name: 'zhangshan',
            f,
            hello() {
                el("i am " + this.name)
            }
        }
        el(obj1.f(1, 1))

        const cart = {
            _wheels: 4,

            get wheels() {
                return this._wheels;
            },

            set wheels(value) {
                if (value < this._wheels) {
                    throw new Error('数值太小了！'); //不会异常捕获
                }
                this._wheels = value;
            }
        }

        var obj3 = {}

        obj3.name = 'foo'
        obj3.age = 11
        obj3['a' + 'ge'] = 12

        var obj4 = {
            name: "foo",
            age: 11,
            ['a']: 12
        }

        const person = {
            sayName() {
                return '...'
            }
        }
        el(person.sayName.name)

        const descriptor = Object.getOwnPropertyDescriptor(cart, 'wheels')
        el(descriptor.get.name)
        el(descriptor.set.name)

        // 特殊情况
        el((new function () {}).name)

        var doSomething = function () {}
        el(doSomething.bind().name)


        const key1 = Symbol('desctiption')
        let obj = {
            [key1]() {},
        }
        el(obj[key1].name)


        // 属性可枚举性和遍历
        var info = {
            name: "dushenyan"
        }


        // 引入枚举enumerable最初目的 让某些原型可以规避掉for..in操作 不然内部所有属性和方法都会被遍历
        el(Object.getOwnPropertyDescriptor(info.__proto__, 'toString').enumerable) //false

        // 返回一个数组 包含对象自身所有可枚举属性
        el(Object.keys(info))

        //返回数组 包含对象自身所有属性键名
        el(Object.getOwnPropertyNames(info))

        // 返回数组 包含对象自身所有Symbol属性键名
        el(Object.getOwnPropertyDescriptor(info, 'name'))

        //返回数组 包含对象自身的（不含继承的）所有键名，不管键名是 Symbol 或字符串，也不管是否可枚举
        el(Reflect.ownKeys(info))

        var stuInfo = {
            name:'jaijia',
            sayName(){
                return super.name
            }
        }

        Object.setPrototypeOf(stuInfo,info);
        el(stuInfo)
        el(stuInfo.sayName())
    </script>
</body>

</html>